home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / blizkick / modules / speedychip.asm < prev    next >
Assembly Source File  |  2000-02-16  |  4KB  |  172 lines

  1. ; FILE: Source:modules/SpeedyChip.ASM          REV: 2 --- Patch 060 MMU list for faster chipmem write
  2.  
  3. ;
  4. ; SpeedyChip module for BlizKick
  5. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. ; SpeedyChip module patches 060 MMU list speeding up chip memory
  7. ; writes.
  8. ;
  9. ; This module does the same thing as speedychip
  10. ; (Aminet: util/boot/speedychip.lha) by Harry Sintonen (that's me!-)
  11. ;
  12. ; NOTE: If you have V42+ 68060.library you don't need this module.
  13. ;
  14. ; Written by Harry Sintonen.
  15. ; This source code is Public Domain.
  16. ;
  17. ;
  18.  
  19.     incdir    "include:"
  20.     include    "exec/libraries.i"    ; Some required...
  21.     include    "exec/memory.i"
  22.     include    "exec/execbase.i"
  23.     include    "exec/exec_lib.i"
  24.     include    "blizkickmodule.i"
  25.  
  26.     SECTION    MODULE,CODE
  27. _DUMMY_LABEL
  28.  BK_MOD BKMF_SingleMode,_end,(RTF_AFTERDOS)<<24!37<<16!NT_UNKNOWN<<8!(256-110),_name,_idstr,_init
  29.  
  30. ; Singlemode on,
  31. ; AFTERDOS module, requires KS V37.x or better, module type NT_UNKNOWN, priority -110.
  32. ; -> after ramlib (ramlib patches OpenLibrary).
  33.  
  34. _init    movem.l    d0-d1/a0-a2/a6,-(sp)
  35.     move.l    (4).w,a6
  36.     btst    #AFB_68040,(AttnFlags+1,a6) ; Test for 040+
  37.     beq.b    .exit
  38.  
  39.     move.l    #PATCH_LEN+4,d0        ; get memory for patch
  40.     moveq    #MEMF_PUBLIC,d1
  41.     jsr    (_LVOAllocMem,a6)
  42.     tst.l    d0
  43.     beq    .exit
  44.     move.l    d0,a2
  45.  
  46.     lea    (Patch,pc),a0        ; copy patch code
  47.     lea    (4,a2),a1
  48.     move.l    #PATCH_LEN,d0
  49.     jsr    (_LVOCopyMem,a6)
  50.  
  51.     jsr    (_LVOForbid,a6)        ; install patch
  52.     move.l    a2,d0
  53.     addq.l    #4,d0
  54.     move.w    #_LVOOpenLibrary,a0
  55.     move.l    a6,a1
  56.     jsr    (_LVOSetFunction,a6)
  57.     move.l    d0,(a2)
  58.     jsr    (_LVOCacheClearU,a6)
  59.     jsr    (_LVOPermit,a6)
  60.  
  61. .exit    movem.l    (sp)+,d0-d1/a0-a2/a6
  62.     rts
  63.  
  64. Patch
  65. .origol    EQU    *-4
  66.     move.l    (.origol,pc),a0
  67.     cmp.l    #'6804',(a1)        ; match for '68040.library'
  68.     bne.b    .orig
  69.     cmp.l    #'0.li',(4,a1)
  70.     bne.b    .orig
  71.     cmp.l    #'brar',(8,a1)
  72.     bne.b    .orig
  73.     cmp.w    #'y'<<8,(12,a1)
  74.     bne.b    .orig
  75.  
  76.     jsr    (a0)            ; try opening it
  77.     move.l    d0,-(sp)        ; if opened 060 flag & MMU
  78.     beq.b    .exit            ; should be initialized ok.
  79.  
  80.     tst.b    (AttnFlags+1,a6)    ; test for 060
  81.     bmi.b    .has_060
  82.  
  83. .exit    move.l    (sp)+,d0
  84.     rts
  85. .orig    jmp    (a0)
  86.  
  87. .has_060    move.l    a5,a0            ; get MMU control register
  88.     lea    (.gettcr,pc),a5
  89.     jsr    (_LVOSupervisor,a6)
  90.     tst.w    d0            ; test bit 15  E - Enable
  91.     bpl.b    .exit
  92.     btst    #14,d0            ; P - Page Size
  93.     bne.b    .exit            ; Must have 4k page size
  94.  
  95.     movem.l    d2-d3/a4-a5,-(sp)    ; store some regs
  96.     jsr    (_LVODisable,a6)    ; no others messing around, please...
  97.  
  98.     lea    (Patch,pc),a5        ; remove (or disable) patch:
  99.     move.w    #_LVOOpenLibrary,a0
  100.     cmp.l    2(a6,a0.w),a5
  101.     bne.b    .cant_rem
  102.     move.l    -(a5),d0
  103.     move.l    a6,a1
  104.     jsr    (_LVOSetFunction,a6)
  105.     bra.b    .was_remd
  106. .cant_rem    move.w    #$4ED0,(4,a5)        ; disable patch
  107.     jsr    (_LVOCacheClearU,a6)
  108. .was_remd
  109.     lea    (.geturp,pc),a5        ; get MMU list root table
  110.     jsr    (_LVOSupervisor,a6)
  111.     move.l    d0,a0            ; a0=array of 128 root-level table descriptors, 32mb each
  112.  
  113.     move.l    (a0),d0            ; get first pointer table
  114.     and.w    #$FE00,d0
  115.     move.l    d0,a4            ; a4=array of 128 pointer table descriptors, 256k each
  116.  
  117.     moveq    #8-1,d3            ; Patch all page desciptors of first 8 table
  118. .mloop    move.l    (a4)+,d0        ; descriptors (8*256k=2mb=size of chipmem)
  119.     and.w    #$FE00,d0
  120.     move.l    d0,a0            ; a0=array of 64 page descriptors
  121.     moveq    #64-1,d1
  122. .ploop    move.l    (a0),d2
  123.     move.l    d2,d0
  124.     and.b    #%11,d0            ; get PDT
  125.     beq.b    .next            ; 00=invalid
  126.     cmp.b    #%10,d0            ; 10=indirect
  127.     beq.b    .next
  128.  
  129.     ; ok this is really it:
  130.     or.b    #%1100000,d2        ; set cm (bits 5&6) to 11 (Cache-Inhibited, Imprecise exception model)
  131.     move.l    d2,(a0)
  132.  
  133. .next    addq.l    #4,a0
  134.     dbf    d1,.ploop
  135.     dbf    d3,.mloop
  136.  
  137.     lea    (.flush,pc),a5        ; flush ATC & caches
  138.     jsr    (_LVOSupervisor,a6)
  139.     jsr    (_LVOCacheClearU,a6)    ; flush caches with OS too (just to be sure:)
  140.     jsr    (_LVOEnable,a6)        ; and back...
  141.     movem.l    (sp)+,d2-d3/a4-a5    ; pop registers
  142.     move.l    (sp)+,d0        ; pop OpenLibrary() result.
  143.     rts
  144.  
  145. .gettcr    move.l    a0,a5
  146.     dc.l    $4E7A0003        ;movec    tc,d0
  147.     nop
  148.     rte
  149.  
  150. .geturp    dc.l    $4E7A0806        ;movec    urp,d0
  151.     nop
  152.     rte
  153.  
  154. .flush    dc.w    $F518    ; PFLUSHA    flush the address translation cache
  155.     dc.w    $F4F8    ; CPUSHA BC    flush the caches into memory
  156.     dc.w    $F4D8    ; INVA  BC    invalidate the data and inst caches
  157.      nop
  158.     rte
  159.  
  160.  
  161. PATCH_LEN    EQU    *-Patch
  162.  
  163. _name    dc.b    'SpeedyChip',0
  164. _idstr    dc.b    'SpeedyChip 1.1 (3.12.97)',0
  165.     CNOP    0,2
  166. _end
  167.  
  168.     SECTION    VERSION,DATA
  169.  
  170.     dc.b    '$VER: SpeedyChip_MODULE 1.1 (3.12.97)',0
  171.  
  172.